<template>
  <div>
    <el-dialog
      :modelValue="visible"
      :width="width"
      :draggable="draggable"
      :show-close="false"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      center
      class="singalr-modal"
    >
      <div class="progress-container">
        <div class="progress-header">
          <div class="progress-icon-wrapper">
            <div class="progress-icon">
              <el-icon class="loading-icon">⏳</el-icon>
            </div>
            <h3 class="progress-title">处理进度</h3>
            <p class="progress-subtitle">{{ discontinueFont === "中止" ? "正在处理您的请求..." : "操作已暂停" }}</p>
          </div>
        </div>

        <div class="progress-section">
          <div class="progress-bar-container">
            <div class="progress-header-row">
              <span class="progress-label">处理进度</span>
              <span class="progress-percentage">{{ percentage || 0 }}%</span>
            </div>
            <div class="progress-bar-wrapper">
              <div class="progress-bar-bg"></div>
              <div class="progress-bar-fill" :style="{ width: `${percentage || 0}%` }"></div>
              <div class="progress-bar-glow"></div>
            </div>
          </div>

          <div class="progress-controls">
            <div class="progress-status">
              <div class="status-indicator" :class="{ active: discontinueFont === '中止' }">
                <div class="status-dot"></div>
                <span class="status-text">{{ discontinueFont === "中止" ? "处理中" : "已暂停" }}</span>
              </div>
            </div>

            <div class="control-buttons">
              <el-button
                @click="cease"
                :type="discontinueFont === '中止' ? 'warning' : 'success'"
                class="control-btn primary-btn"
                size="default"
              >
                <el-icon class="btn-icon">
                  {{ discontinueFont === "中止" ? "⏸️" : "▶️" }}
                </el-icon>
                {{ discontinueFont }}
              </el-button>
              <el-button type="danger" @click="cancel" class="control-btn danger-btn" size="default">
                <el-icon class="btn-icon">❌</el-icon>
                取消
              </el-button>
            </div>
          </div>
        </div>

        <div class="progress-details">
          <div class="details-content">
            <slot></slot>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  draggable: {
    type: Boolean,
    default: true
  },
  title: {
    type: String,
    default: ""
  },
  width: {
    type: String,
    default: "520px"
  },
  height: {
    type: String,
    default: "300"
  },
  discontinueFont: {
    type: String,
    default: "中止"
  },
  percentage: {
    type: Number,
    default: 0
  }
});

const emit = defineEmits(["update:visible", "cease", "cancel"]);

const cancel = () => {
  emit("cancel");
};

const cease = () => {
  emit("cease");
};
</script>

<style lang="scss" scoped>
:deep(.singalr-modal) {
  display: flex;
  align-items: center;
  justify-content: center;
}
:deep(.el-dialog) {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: 0 auto !important;
  overflow: hidden;
  background: white !important;
  border: 1px solid rgb(255 255 255 / 10%);
  border-radius: 16px;
  box-shadow: 0 25px 80px rgb(0 0 0 / 12%), 0 8px 32px rgb(0 0 0 / 8%);
  transform: translate(-50%, -50%);
}
:deep(.el-dialog__header) {
  display: none;
}
:deep(.el-dialog__body) {
  width: 100%;
  min-width: 0;
  padding: 0 !important;
}
.progress-container {
  position: relative;
  padding: 32px 28px;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  &::before {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 1px;
    content: "";
    background: linear-gradient(90deg, transparent 0%, rgb(var(--el-color-primary-rgb) 0.1) 50%, transparent 100%);
  }
}
.progress-header {
  margin-bottom: 20px;
}
.progress-header-top {
  margin-bottom: 24px;
  text-align: center;
}
.progress-icon-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 16px;
}
.progress-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--el-color-primary) 0%, var(--el-color-primary-dark-2) 100%);
  border-radius: 50%;
  box-shadow: 0 6px 24px rgb(var(--el-color-primary-rgb) 0.3);
  margin-bottom: 12px;
}
.loading-icon {
  font-size: 24px;
  color: white;
  animation: pulse 2s ease-in-out infinite;
}
.progress-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  color: #1f2937;
  letter-spacing: -0.025em;
}
.progress-subtitle {
  margin: 0;
  font-size: 15px;
  font-weight: 400;
  color: #6b7280;
}
.progress-section {
  margin-bottom: 24px;
}
.progress-bar-container {
  position: relative;
  margin-bottom: 16px;
}
.progress-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.progress-label {
  font-size: 14px;
  font-weight: 500;
  color: #6b7280;
}
.progress-percentage {
  padding: 3px 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--el-color-primary);
  background: rgb(var(--el-color-primary-rgb) 0.1);
  border: 1px solid rgb(var(--el-color-primary-rgb) 0.2);
  border-radius: 14px;
}
.progress-bar-wrapper {
  position: relative;
  height: 14px;
  overflow: hidden;
  background: #f3f4f6;
  border: 1px solid rgb(0 0 0 / 5%);
  border-radius: 8px;
  box-shadow: inset 0 1px 3px rgb(0 0 0 / 10%);
}
.progress-bar-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #e5e7eb 0%, #d1d5db 100%);
  border-radius: 8px;
}
.progress-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--el-color-primary) 0%, var(--el-color-primary-dark-2) 100%);
  border-radius: 8px;
  box-shadow: 0 0 20px rgb(var(--el-color-primary-rgb) 0.4);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-bar-glow {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgb(var(--el-color-primary-rgb) 0.1) 50%, transparent 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.progress-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}
.progress-status {
  display: flex;
  justify-content: flex-start;
}
.control-buttons {
  display: flex;
  gap: 12px;
}
.status-indicator {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  transition: all 0.3s ease;
}
.status-indicator.active {
  background: rgb(var(--el-color-primary-rgb) 0.1);
  border-color: var(--el-color-primary);
}
.status-dot {
  width: 7px;
  height: 7px;
  margin-right: 6px;
  background: #9ca3af;
  border-radius: 50%;
  transition: all 0.3s ease;
}
.status-indicator.active .status-dot {
  background: var(--el-color-primary);
  box-shadow: 0 0 0 4px rgb(var(--el-color-primary-rgb) 0.2);
}
.status-text {
  font-size: 13px;
  font-weight: 500;
  color: #374151;
}
.progress-details .details-content {
  padding: 16px;
  text-align: center;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
}
.control-btn {
  position: relative;
  min-width: 90px;
  height: 36px;
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 6px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.btn-icon {
  margin-right: 5px;
  font-size: 13px;
  transition: color 0.3s ease;
}
.primary-btn .btn-icon {
  color: currentColor;
}
.danger-btn .btn-icon {
  color: currentColor;
}
.primary-btn {
  color: white;
  background: linear-gradient(135deg, var(--el-color-primary) 0%, var(--el-color-primary-dark-2) 100%);
  border: 1px solid var(--el-color-primary);
}
.primary-btn:hover {
  color: var(--el-color-primary-dark-2);
  background: linear-gradient(135deg, var(--el-color-primary-light-3) 0%, var(--el-color-primary-light-5) 100%);
  border-color: var(--el-color-primary);
  box-shadow: 0 8px 25px rgb(var(--el-color-primary-rgb) 0.3);
  transform: translateY(-2px);
}
.danger-btn {
  color: white;
  background: linear-gradient(135deg, var(--el-color-danger) 0%, var(--el-color-danger-dark-2) 100%);
  border: 1px solid var(--el-color-danger);
}
.danger-btn:hover {
  color: var(--el-color-danger-dark-2);
  background: linear-gradient(135deg, var(--el-color-danger-light-3) 0%, var(--el-color-danger-light-5) 100%);
  border-color: var(--el-color-danger);
  box-shadow: 0 8px 25px rgb(var(--el-color-danger-rgb) 0.3);
  transform: translateY(-2px);
}
.control-btn:active {
  transform: translateY(0);
}
.control-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgb(var(--el-color-primary-rgb) 0.2);
}
.control-btn:focus-visible {
  outline: 2px solid var(--el-color-primary);
  outline-offset: 2px;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

@media (max-width: 768px) {
  .progress-container {
    padding: 28px 20px;
  }
  .progress-title {
    font-size: 20px;
  }
  .progress-subtitle {
    font-size: 14px;
  }
  .progress-controls {
    flex-direction: column;
    gap: 16px;
    align-items: center;
  }
  .control-buttons {
    justify-content: center;
    width: 100%;
  }
  .progress-header-row {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }
  .progress-percentage {
    padding: 3px 10px;
    font-size: 14px;
  }
  .control-btn {
    min-width: 100px;
    height: 40px;
    font-size: 14px;
  }
}
</style>
